package org.jeecg.zhenxuan.Repository;

import org.jeecg.zhenxuan.Entity.PointFlow;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;


@Repository
public interface PointFlowRepository extends JpaRepository<PointFlow,Integer>, JpaSpecificationExecutor<PointFlow> {

    @Query(countQuery = "select * from PointFlow where Id =:Id and operation ='reduce'", nativeQuery = true)
    public PointFlow getPointFlowById(Integer Id);

    @Query(value = "select max(id) from PointFlow where openId =:pfopenId and operation ='reduce'" )
    public Integer getMax(@Param("pfopenId") String pfopenId);


    public PointFlow findPointFlowByOpenIdAndId(String openId, Integer id);

    public Integer countPointFlowsByOpenId(String openId);

    @Modifying(clearAutomatically = true)
    @Query(nativeQuery = true, value = "update pointflow set openId = :tempId where openId = :openId")
    public int updatePointFlowOpenId(@Param("openId") String openId, @Param("tempId") String tempId);

}
